package wechat.app.test

import org.junit.Ignore
import org.junit.Test
import wechat.app.WXCorpAppFactory
import wechat.app.util.PropertyReader

class MessageTest {
	private static String CALLBACK_SERVER_URL = "http://58.247.87.218:8090"
	private static String MOBILD_CALLBACK_SERVER_URL = "http://mobileangularui.com/demo"
	String callbackurl
	@Test
	@Ignore
	def void configTest(){
		val propertyReader = new PropertyReader();
		println('PropertyReader::corpId======='+ propertyReader.corpId)
		println('PropertyReader::SECRET======='+ propertyReader.SECRET)
		println('PropertyReader::AGENTID======='+ propertyReader.AGENTID)
		WXCorpAppFactory::getDefaultCorpApp=>[
			createNews()=>[
				callbackurl = generateUrl("redirect","rockweixinid","rock","11111", "测试任务", "测试任务描述")
				withItem('新消息')=>[
					picurl = CALLBACK_SERVER_URL+"/sample.jpg"
					url= callbackurl
				]
				withItem('任务名称:测试任务\n\r任务描述:测试任务描述')=>[
					picurl = CALLBACK_SERVER_URL+"/smallsample.jpg"
					url= callbackurl
				]
				send2Users(newArrayList(''))
			]
		]
	}
//	@Test
//	@Ignore
//	def void dslWebPageTest(){
//		
//		WXCorpAppFactory::customerApp=>[
//			createNews()=>[
//				callbackurl = generateUrl("redirect","rockweixinid","rock","11111", "测试任务", "测试任务描述")
//				withItem('新消息')=>[
//					picurl = CALLBACK_SERVER_URL+"/sample.jpg"
//					url= callbackurl
//				]
//				withItem('任务名称:测试任务\n\r任务描述:测试任务描述')=>[
//					picurl = CALLBACK_SERVER_URL+"/smallsample.jpg"
//					url= callbackurl
//				]
//				send2Users(newArrayList('@all'))
//			]
//		]
//	}
	
	@Test
	@Ignore
	def void dslSendScheduledTest(){
//		ScheduledTaskNotify::sendMsg("rock20110501","test","test","test")
	}
	@Test
	@Ignore
	def void dslSendMessageTest(){
		WXCorpAppFactory::getDefaultCorpApp=>[
			createNews()=>[
				withItem('新消息')=>[
//					picurl = CALLBACK_SERVER_URL+"/sample.jpg"
//					url= generateUrl("","","11111", "测试任务", "测试任务描述")
				]
				withItem('任务名称:测试任务\n\r任务描述:测试任务描述')=>[
//					picurl = CALLBACK_SERVER_URL+"/smallsample.jpg"
//					url= generateUrl("","","11111", "测试任务", "测试任务描述")
				]
				send2Users(newArrayList('r93128'))
			]
		]
	}
	@Test
	@Ignore
	def void dslSendMessageDirect3MobildUITest(){
		WXCorpAppFactory::getDefaultCorpApp=>[
			createNews()=>[
				withItem('新消息')=>[
					picurl = CALLBACK_SERVER_URL+"/sample.jpg"
					url= generateUrl("","","11111", "测试任务", "测试任务描述")
				]
				withItem('任务名称:测试任务\n\r任务描述:测试任务描述')=>[
					picurl = CALLBACK_SERVER_URL+"/smallsample.jpg"
					url= MOBILD_CALLBACK_SERVER_URL
				]
				send2Users(newArrayList('ztiange-'))
			]
		]
	}
	@Test
	@Ignore
	def void dslUploadTmpFileTest(){
		WXCorpAppFactory::getDefaultCorpApp=>[
			uploadTmpFile("sample.jpg")=>[
			println("\nmedia_id is "+media_id)	
			]
		]
	}
	@Test
	@Ignore
	def void dslSendMpNewsTest(){
		WXCorpAppFactory::getDefaultCorpApp=>[
			createMPNews()=>[
				withItem('新消息')=>[
					thumb_media_id = "1lbyj8sNRzr-Y4g9yLR_yg05jCum73B3QJiSSa3jPpDygbs03JrdOuscuVxeuT-QMNZLIZLZTi5-p3AN1Ngnb2A"
					content ="test"
				]
				send2Users(newArrayList('ztiange-'))
			]
		]
	}
	
	def generateUrl(String who, String id, String task_id,String project_name, String task_desc) {
			 CALLBACK_SERVER_URL+"/"+"taskdetails"+"?who="+who +"&assigneeid="+id
				+"&taskid="+task_id
				+"&projectname="+project_name
				+"&taskdesc="+task_desc
	}
	def generateUrl(String request,String who, String id, String task_id,String project_name, String task_desc) {
			 CALLBACK_SERVER_URL+"/"+request+"?who="+who +"&assigneeid="+id
				+"&taskid="+task_id
				+"&projectname="+project_name
				+"&taskdesc="+task_desc
	}
}